package helper

import (
	"github.com/go-playground/validator/v10"
	"sync"
)

var validate *validator.Validate

/*func init() {
	validate = validator.New()
}*/

var validateOnce sync.Once

// 获取validator 实例
func GetValidator() *validator.Validate {
	if validate != nil {
		return validate
	}
	validateOnce.Do(func() {
		validate = validator.New()
		_ = validate.RegisterValidation("phone", validatePhone)
	})

	return validate
}

func validatePhone(fl validator.FieldLevel) bool {
	return CheckPhone(fl.Field().String())
}
